<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0"/>
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			body{
				position: absolute;
			}
			#box{
				width: 150px;
				height: 150px;
				background: red;
				position: absolute;
			}
		</style>
	</head>
	<body>
		<div id="box">
			
		</div>
	</body>
	<script type="text/javascript">
		var box = document.querySelector("#box");
		var disX = 0;
		var disY = 0;
		function startFn(event){
			if(event.touches.length == 1){
				var touch = event.touches[0];
			}
			disX = touch.clientX - box.offsetLeft;
			disY = touch.clientY - box.offsetTop;
		}
		box.addEventListener("touchstart",startFn,false);
		box.addEventListener("touchmove",moveFn,false);
		box.addEventListener("touchend",endFn,false);
		function moveFn(event){
			event.preventDefault();
			if(event.touches.length == 1){
				var touch = event.touches[0];
			}
			var x = touch.clientX - disX;
			var y = touch.clientY - disY;
			box.style.left = x + "px";
			box.style.top = y + "px";	
		}
		function endFn(){
			alert("触摸结束");
		}
	</script>
</html>
